package com.foreknow.demo15;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class TestStudent {
    /**
     * 定义输出学生信息的方法
     */
    public void printInfo(List<Student> list) {
        //遍历输出学生信息
//        for (Student xx:list) {
//            System.out.println(xx.getName());
//        }
//
//        for(int i = 0;i<list.size();i++) {
//            Student ss = list.get(i);
//            System.out.println(ss.getName());
//        }
        Iterator<Student> it = list.iterator();
        while (it.hasNext()) {
            Student s = it.next();
            System.out.println(s.getName());
        }
    }


    public static void main(String[] args) {
        //输入三次学生信息
        //每输入一次学生信息，就要将这个学生以对象的方式保存到List集合中
        //遍历List集合，输出每个学生的信息
        Scanner input = new Scanner(System.in);
        List<Student> list = new ArrayList<>();
        for(int i = 0;i < 3;i++) {
            Student student = new Student();
            System.out.println("请输入学号: ");
            String sid = input.next();
            System.out.println("请输入姓名: ");
            String name = input.next();
            System.out.println("请输入电话: ");
            String phone = input.next();
            student.setSid(sid);
            student.setName(name);
            student.setPhone(phone);
            //将学生对象添加到list集合中
            list.add(student);
        }

        TestStudent test = new TestStudent();
        test.printInfo(list);
    }
}
